package com.StarStudio.Service.Impl;

import cn.hutool.core.util.IdUtil;
import com.StarStudio.DAO.RateDAO;
import com.StarStudio.Service.RateService;
import com.ruoyi.common.core.Entity.Rate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class RateServiceImpl implements RateService {

    @Autowired
    RateDAO rateDAO;

    @Override
    public List<Rate> findRateList(Rate rate) {
        return rateDAO.findRateList(rate);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addRate(Rate rate) {
        rate.setId(IdUtil.getSnowflakeNextId());
        rate.setCreateTime(new Date());
        rateDAO.addRate(rate);
    }

    @Override
    public Rate findCurrentRate() {
        return rateDAO.findCurrentRate();
    }
}
